<?php
/**
 * 金额导入模型
 * @author jianhui
 * 
 *
 */
class importMoneyModel extends MY_Model{
    var $typeCon = array(
        11 => '专营店营销基金-全年营销费用',
        12 => '专营店营销基金-最终结算金额',
        21 => '区域营销基金-双月额度',
        31 => '车展基金-双月额度',
        41 => '巡展基金-双月额度',
        51 => '专项基金-双月额度',
    );
    function importMoneyModel(){
        parent::MY_Model();
        $this->table = 'ImportMoney';
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list = array()){
        //时间单位配置
        $this->CI->load->model('timeUnitModel');
        $timeUnitList = $this->CI->timeUnitModel->getCacheData('timeUnitList');
        foreach ($list as $k => $v){
            $list[$k]['typeStr'] = isset($this->typeCon[$v['type']]) ? $this->typeCon[$v['type']] : '';
            //时间单位
            $list[$k]['timeUnitStr'] = isset($timeUnitList[$v['year']][$v['timeUnit']]) ? $timeUnitList[$v['year']][$v['timeUnit']] : '';
        }
        return $list;
    }
    /**
     * 获取类型名称
     * @param number $type
     */
    function getTypeName($type){
        return isset($this->typeCon[$type]) ? $this->typeCon[$type] : '';
    }
    /**
     * 获取指定导入类别金额
     * @param int $storeId 店铺用户ID
     * @param int $timeUnit 时间单位
     * @param int $type 金额类别
     * @param number $year 年份
     * @return number
     */
    function getMoney($storeId, $timeUnit, $type , $year = 2015){
        $findData = $this->getData(array('storeId'=>$storeId, 'timeUnit'=>$timeUnit, 'year'=>$year, 'type'=>$type));
        return isset($findData) && $findData['money'] ? (float)$findData['money'] : 0;
    }
}